//package com.rayo.accesscontrollercopy.model.biz;
//
//import android.util.Log;
//
//import com.alibaba.fastjson.JSONArray;
//import com.litesuits.common.utils.HexUtil;
//import com.rayo.accesscontrollercopy.config.GlobalVariables;
//import com.rayo.accesscontrollercopy.model.callback.OnReaderListener;
//import com.rayo.accesscontrollercopy.model.db.bean.CardTimezoneData;
//import com.rayo.accesscontrollercopy.model.db.bean.CardUserData;
//import com.rayo.accesscontrollercopy.model.db.bean.DSTData;
//import com.rayo.accesscontrollercopy.model.db.bean.HeartData;
//import com.rayo.accesscontrollercopy.model.db.bean.KeyTimezoneData;
//import com.rayo.accesscontrollercopy.model.db.bean.KeyUserData;
//import com.rayo.accesscontrollercopy.model.db.bean.PlanKeyAdd;
//import com.rayo.accesscontrollercopy.model.db.bean.PlanKeyAddData;
//import com.rayo.accesscontrollercopy.model.db.bean.PlanKeyDel;
//import com.rayo.accesscontrollercopy.model.db.bean.PlanKeyDelData;
//import com.rayo.accesscontrollercopy.model.db.dao.CardTimeDao;
//import com.rayo.accesscontrollercopy.model.db.dao.CardTimeImpl;
//import com.rayo.accesscontrollercopy.model.db.dao.CardUserDao;
//import com.rayo.accesscontrollercopy.model.db.dao.CardUserImpl;
//import com.rayo.accesscontrollercopy.model.db.dao.DSTDao;
//import com.rayo.accesscontrollercopy.model.db.dao.DSTImpl;
//import com.rayo.accesscontrollercopy.model.db.dao.HeartDao;
//import com.rayo.accesscontrollercopy.model.db.dao.HeartImpl;
//import com.rayo.accesscontrollercopy.model.db.dao.KeyTimeDao;
//import com.rayo.accesscontrollercopy.model.db.dao.KeyTimeImpl;
//import com.rayo.accesscontrollercopy.model.db.dao.KeyUserDao;
//import com.rayo.accesscontrollercopy.model.db.dao.KeyUserImpl;
//import com.rayo.accesscontrollercopy.model.db.dao.PlanKeyAddDao;
//import com.rayo.accesscontrollercopy.model.db.dao.PlanKeyAddImpl;
//import com.rayo.accesscontrollercopy.model.db.dao.PlanKeyDelDao;
//import com.rayo.accesscontrollercopy.model.db.dao.PlanKeyDelImpl;
//import com.rayo.accesscontrollercopy.model.service.ReaderService;
//import com.rayo.wallreader.data.CardBasicInfo;
//import com.rayo.wallreader.data.CardTypeEnum;
//import com.rayo.wallreader.data.KeyBasicInfo;
//import com.rayo.wallreader.data.KeyEventInfo;
//import com.rayo.wallreader.data.KeyType;
//import com.rayo.wallreader.data.ProCardInfo;
//import com.rayo.wallreader.data.ProKeyInfo;
//import com.rayo.wallreader.data.UserCardInfo;
//import com.rayo.wallreader.data.UserKeyInfo;
//import com.rayo.wallreader.jni.WallreaderJni;
//import com.rayo.wallreader.serialport.OnPortListener;
//import com.rayo.wallreader.serialport.ReaderPort;
//import com.rayo.wallreader.serialport.ReaderPortThread;
//import com.rayo.wallreader.utils.TimeUtils;
//
//import java.util.ArrayList;
//import java.util.Calendar;
//import java.util.Date;
//import java.util.List;
//
///**
// * Created by yanghaojie on 16/7/26.
// */
//public class ReaderBiz implements IReaderBiz {
//    private ReaderPortThread mReaderPortThread;
//    private String mPortName;
//
//    private OnReaderListener onFindKeyListener, onFindCardListener;
//    private KeyBasicInfo keyBasicInfo;
//    private CardBasicInfo cardBasicInfo;
//    private UserKeyInfo mUserKeyInfo;
//    private UserCardInfo mUserCardInfo;
//    private boolean mIsUpdateKey;
//
//    public static final int INSET_READER = 1;
//    public static final int PLUG_IN_READER = 2;
//
//    public static final int BEEP_SUCCESS = 1;
//    public static final int BEEP_FAILED = 0;
//    public static final int BEEP_CONNECT_BREAK = 2;
//
//    public static final int ERROR_CONNECT = 0;
//    public static final int ERROR_USER_IN_BLACK = 1;
//
//    public ReaderBiz() {
//        this.keyBasicInfo = new KeyBasicInfo();
//        this.cardBasicInfo = new CardBasicInfo();
//    }
//
//    public ReaderBiz(int port, boolean key, boolean card) {
//        if (INSET_READER == port) mPortName = ReaderPort.DETIVER_0;
//        else mPortName = ReaderPort.DETIVER_1;
//
//        this.keyBasicInfo = new KeyBasicInfo();
//        this.cardBasicInfo = new CardBasicInfo();
//        byte[] code = new byte[16];
//        byte[] sys_Code = HexUtil.decodeHex(GlobalVariables.getInstance().getmSiteData().getSyscode().toCharArray());
//        if (null != sys_Code && 8 == sys_Code.length) {
//            int ret = WallreaderJni.getmInstance().des(1,sys_Code, sys_Code.length, code);
//            if (ret > 0) {
//                System.arraycopy(code, 0, this.keyBasicInfo.getSysCode(), 0, 4);
//                System.arraycopy(code, 0, this.cardBasicInfo.getRegCode(), 0, 4);
//            }
//        }
//        byte[] reg_Code = HexUtil.decodeHex(GlobalVariables.getInstance().getmSiteData().getRegcode().toCharArray());
//        if (null != reg_Code && 8 == reg_Code.length) {
//            int ret = WallreaderJni.getmInstance().des(1,sys_Code, reg_Code.length, code);
//            if (ret > 0) {
//                System.arraycopy(code, 0, this.keyBasicInfo.getRegCode(), 0, 4);
//                System.arraycopy(code, 0, this.cardBasicInfo.getRegCode(), 0, 4);
//            }
//        }
//        mReaderPortThread = new ReaderPortThread(mPortName, key, card) {
//            @Override
//            protected void onSendKeyReader() {
//                FindKey(onFindKeyListener);
//            }
//
//            @Override
//            protected void onSendCardReader() {
//                FindCard(onFindCardListener);
//            }
//        };
//    }
//
//    @Override
//    public void onPause() {
//        if (null != mReaderPortThread)
//            mReaderPortThread.onPause();
//    }
//
//    @Override
//    public void onResume() {
//        if (null != mReaderPortThread)
//            mReaderPortThread.onResume();
//    }
//
//    @Override
//    public void onDestroy() {
//        if (null != mReaderPortThread)
//            mReaderPortThread.stop();
//    }
//
//    @Override
//    public Runnable getRunnable(OnReaderListener onReaderKeyListener, OnReaderListener onReaderCardListener) {
//        this.onFindKeyListener = onReaderKeyListener;
//        this.onFindCardListener = onReaderCardListener;
//        return mReaderPortThread;
//    }
//
//    @Override
//    public void beep(int type, OnPortListener.OnBeepListener onBeepListener) {
//        mReaderPortThread.getmPortReadBiz().beep(type, onBeepListener);
//    }
//
//    @Override
//    public void FindKey(final OnReaderListener onReaderListener) {
//        mReaderPortThread.getmPortReadBiz().findKey(this.keyBasicInfo, new OnPortListener.OnFindKeyListener() {
//            @Override
//            public void findKeySuccess() {
//                if (mIsUpdateKey) {
//                    mReaderPortThread.getmPortReadBiz().writeUserKey(keyBasicInfo, mUserKeyInfo, new OnPortListener.OnWriteUserKeyListener() {
//                        @Override
//                        public void writeUserKeySuccess() {
//                            onReaderListener.readerSuccessfully(ReaderService.ACTION_READER_WRITE_USERKEY, mUserKeyInfo);
//                            KeyCanOpen(GlobalVariables.getInstance().getmSiteData().getLockid(),
//                                    GlobalVariables.getInstance().getmSiteData().getGroupid(), onReaderListener);
//                            mIsUpdateKey = false;
//                        }
//
//                        @Override
//                        public void writeUserKeyFailed() {
//                            onReaderListener.readerFailed(ReaderService.ACTION_READER_WRITE_USERCARD, 0);
//                            beep(BEEP_CONNECT_BREAK, mOnBeepListener);
//                            mIsUpdateKey = false;
//                        }
//                    });
//                } else {
//                    onReaderListener.readerSuccessfully(ReaderService.ACTION_READER_FIND_KEY, keyBasicInfo);
//                    KeyType key = KeyType.fromInt(keyBasicInfo.getType());
//                    readKey(key, onReaderListener);
//                }
//            }
//
//            @Override
//            public void findKeyFailed() {
//                onReaderListener.readerFailed(ReaderService.ACTION_READER_FIND_KEY, ERROR_CONNECT);
//                beep(BEEP_CONNECT_BREAK, mOnBeepListener);
//            }
//        });
//    }
//
//    @Override
//    public void FindCard(final OnReaderListener onReaderListener) {
//        mReaderPortThread.getmPortReadBiz().findCard(this.cardBasicInfo, new OnPortListener.OnFindKeyListener() {
//            @Override
//            public void findKeySuccess() {
//                onReaderListener.readerSuccessfully(ReaderService.ACTION_READER_FIND_CARD, cardBasicInfo);
//                CardTypeEnum cardTypeEnum = CardTypeEnum.fromInt(cardBasicInfo.getCardType());
//                readCard(cardTypeEnum, onReaderListener);
//            }
//
//            @Override
//            public void findKeyFailed() {
//                onReaderListener.readerFailed(ReaderService.ACTION_READER_FIND_CARD, ERROR_CONNECT);
//                beep(BEEP_CONNECT_BREAK, mOnBeepListener);
//            }
//        });
//    }
//
//    @Override
//    public void ReadUserKey(final UserKeyInfo userKeyInfo, final OnReaderListener onReadUserKeyListener) {
//        mReaderPortThread.getmPortReadBiz().readUserKey(keyBasicInfo, userKeyInfo, new OnPortListener.OnReadUserKeyListener() {
//            @Override
//            public void readUserKeySuccess() {
//                onReadUserKeyListener.readerSuccessfully(ReaderService.ACTION_READER_READ_USERKEY, userKeyInfo);
//                ReadKeyEvent(new KeyEventInfo(), onReadUserKeyListener);
//            }
//
//            @Override
//            public void readUserKeyFailed() {
//                onReadUserKeyListener.readerFailed(ReaderService.ACTION_READER_READ_USERKEY, 0);
//                beep(BEEP_CONNECT_BREAK, mOnBeepListener);
//            }
//        });
//    }
//
//    @Override
//    public void ReadProKey(final ProKeyInfo proKeyInfo, final OnReaderListener onReadProKeyListener) {
//        mReaderPortThread.getmPortReadBiz().readProKey(keyBasicInfo, proKeyInfo, new OnPortListener.OnReadProKeyListener() {
//            @Override
//            public void readProKeySuccess() {
//                KeyType key = KeyType.fromInt(keyBasicInfo.getType());
//                onReadProKeyListener.readerSuccessfully(ReaderService.ACTION_READER_READ_PROKEY, proKeyInfo);
//                if (KeyType.EMERGENCY_KEY == key || KeyType.ENG_KEY == key
//                        || KeyType.SETTING_KEY == key || KeyType.EVENT_KEY == key) {
//                    ReadKeyEvent(new KeyEventInfo(), onReadProKeyListener);
//                } else {
//                    beep(BEEP_SUCCESS, mOnBeepListener);
//                }
//            }
//
//            @Override
//            public void readProKeyFailed() {
//                onReadProKeyListener.readerFailed(ReaderService.ACTION_READER_READ_PROKEY, ERROR_CONNECT);
//                beep(BEEP_CONNECT_BREAK, mOnBeepListener);
//            }
//        });
//    }
//
//    @Override
//    public void ReadProCard(final ProCardInfo proCardInfo, final OnReaderListener onReaderListener) {
//        mReaderPortThread.getmPortReadBiz().readProCard(cardBasicInfo, proCardInfo, new OnPortListener.OnReadProKeyListener() {
//            @Override
//            public void readProKeySuccess() {
//                onReaderListener.readerSuccessfully(ReaderService.ACTION_READER_READ_PROCARD, proCardInfo);
//            }
//
//            @Override
//            public void readProKeyFailed() {
//                onReaderListener.readerFailed(ReaderService.ACTION_READER_READ_PROCARD, ERROR_CONNECT);
//                beep(BEEP_CONNECT_BREAK, mOnBeepListener);
//            }
//        });
//    }
//
//    @Override
//    public void ReadUserCard(final UserCardInfo userCardInfo, final OnReaderListener onReadUserKeyListener) {
//        mReaderPortThread.getmPortReadBiz().readUserCard(cardBasicInfo, userCardInfo, new OnPortListener.OnReadUserKeyListener() {
//            @Override
//            public void readUserKeySuccess() {
//                onReadUserKeyListener.readerSuccessfully(ReaderService.ACTION_READER_READ_USERCARD, userCardInfo);
//                UpdateUserCard(cardBasicInfo, userCardInfo, onReadUserKeyListener);
//            }
//
//            @Override
//            public void readUserKeyFailed() {
//                onReadUserKeyListener.readerFailed(ReaderService.ACTION_READER_READ_USERCARD, ERROR_CONNECT);
//                beep(BEEP_CONNECT_BREAK, mOnBeepListener);
//            }
//        });
//    }
//
//    @Override
//    public void ReadKeyEvent(final KeyEventInfo keyEventInfo, final OnReaderListener onReadEventListener) {
//        mReaderPortThread.getmPortReadBiz().readEvent(keyBasicInfo, keyEventInfo, new OnPortListener.OnReadEventListener() {
//            @Override
//            public void readEventSuccess() {
//                onReadEventListener.readerSuccessfully(ReaderService.ACTION_READER_READ_EVENT, keyEventInfo);
//                KeyType key = KeyType.fromInt(keyBasicInfo.getType());
//                if (KeyType.USER_KEY == key) {
//                    UpdateUserKey(keyBasicInfo, mUserKeyInfo, onReadEventListener);
//                }
//            }
//
//            @Override
//            public void readEventFailed() {
//                onReadEventListener.readerFailed(ReaderService.ACTION_READER_READ_EVENT, ERROR_CONNECT);
//                beep(BEEP_CONNECT_BREAK, mOnBeepListener);
//            }
//        });
//    }
//
//    @Override
//    public void KeyCanOpen(int lockId, int groupId, final OnReaderListener onCanOpenListener) {
//        mReaderPortThread.getmPortReadBiz().keyCanOpen(keyBasicInfo, lockId, groupId, new OnPortListener.OnFindKeyListener() {
//            @Override
//            public void findKeySuccess() {
//                onCanOpenListener.readerSuccessfully(ReaderService.ACTION_READER_KEY_OPEN, keyBasicInfo);
//                beep(BEEP_SUCCESS, mOnBeepListener);
//            }
//
//            @Override
//            public void findKeyFailed() {
//                onCanOpenListener.readerFailed(ReaderService.ACTION_READER_KEY_OPEN, 0);
//                beep(BEEP_FAILED, mOnBeepListener);
//            }
//        });
//    }
//
//    @Override
//    public void CardCanOpen(UserCardInfo userCardInfo, int lockId, OnReaderListener onCanOpenListener) {
//        if (null != userCardInfo && userCardInfo.canOpen(lockId)) {
//            onCanOpenListener.readerSuccessfully(ReaderService.ACTION_READER_CARD_OPEN, userCardInfo);
//            beep(BEEP_SUCCESS, mOnBeepListener);
//        } else {
//            onCanOpenListener.readerFailed(ReaderService.ACTION_READER_CARD_OPEN, 0);
//            beep(BEEP_FAILED, mOnBeepListener);
//        }
//    }
//
//    @Override
//    public void UpdateUserKey( KeyBasicInfo keyBasicInfo, UserKeyInfo userKeyInfo, final OnReaderListener onWriteUserKeyListener) {
//        onPause();
//        Calendar calendar = Calendar.getInstance();
//        keyBasicInfo.setKeyTime(TimeUtils.calToBytesYMDWHMS(calendar));
//        mUserKeyInfo= getUserKeyInfo(keyBasicInfo, userKeyInfo);
//        mIsUpdateKey = false;
//        onResume();
//
//        mReaderPortThread.getmPortReadBiz().writeUserKey(keyBasicInfo, userKeyInfo, new OnPortListener.OnWriteUserKeyListener() {
//            @Override
//            public void writeUserKeySuccess() {
//                onWriteUserKeyListener.readerSuccessfully(ReaderService.ACTION_READER_WRITE_USERKEY, mUserKeyInfo);
//                KeyCanOpen(GlobalVariables.getInstance().getmSiteData().getLockid(),
//                        GlobalVariables.getInstance().getmSiteData().getGroupid(), onWriteUserKeyListener);
//            }
//
//            @Override
//            public void writeUserKeyFailed() {
//                onWriteUserKeyListener.readerFailed(ReaderService.ACTION_READER_WRITE_USERKEY, ERROR_CONNECT);
//                beep(BEEP_CONNECT_BREAK, mOnBeepListener);
//            }
//        });
//    }
//
////    @Override
////    public void UpdateUserCard(CardBasicInfo cardBasicInfo, final UserCardInfo userCardInfo, final OnReaderListener onWriteUserKeyListener) {
////        mUserCardInfo = getUserCardInfo(cardBasicInfo, userCardInfo);
////        mReaderPortThread.getmPortReadBiz().writeUserCard(cardBasicInfo, mUserCardInfo, new OnPortListener.OnWriteUserKeyListener() {
////            @Override
////            public void writeUserKeySuccess() {
////                onWriteUserKeyListener.readerSuccessfully(ReaderService.ACTION_READER_WRITE_USERCARD, mUserCardInfo);
////                CardCanOpen(userCardInfo, GlobalVariables.getInstance().getmSiteData().getLockid(), onWriteUserKeyListener);
////            }
////
////            @Override
////            public void writeUserKeyFailed() {
////                onWriteUserKeyListener.readerFailed(ReaderService.ACTION_READER_WRITE_USERCARD, 0);
////                beep(BEEP_CONNECT_BREAK, mOnBeepListener);
////            }
////        });
////    }
//
//    public KeyBasicInfo getKeyBasicInfo() {
//        return keyBasicInfo;
//    }
//
////    public CardBasicInfo getCardBasicInfo() {
////        return cardBasicInfo;
////    }
//
//    private void readKey(KeyType key, OnReaderListener onReaderListener) {
//        if (null == key) {
//            return;
//        }
//        if (KeyType.USER_KEY == key) {
//            mUserKeyInfo = new UserKeyInfo();
//            ReadUserKey(mUserKeyInfo, onReaderListener);
//        } else if (KeyType.EMERGENCY_KEY == key || KeyType.ENG_KEY == key
//                || KeyType.SETTING_KEY == key || KeyType.EVENT_KEY == key
//                || KeyType.LOSS_KEY == key || KeyType.READLOCKID_KEY == key
//                || KeyType.READLOCKNUM_KEY == key || KeyType.SYSCODE_KEY == key) {
//            ReadProKey(new ProKeyInfo(), onReaderListener);
//        } else {
//
//        }
//    }
//
////    private void readCard(CardTypeEnum cardTypeEnum, OnReaderListener onReaderListener) {
////        if (null == cardTypeEnum) return;
////        if (CardTypeEnum.USER_CARD == cardTypeEnum) {
////            mUserCardInfo = new UserCardInfo();
////            ReadUserCard(mUserCardInfo, onReaderListener);
////        } else {
////            ReadProCard(new ProCardInfo(), onReaderListener);
////        }
////    }
//
//    private UserKeyInfo getUserKeyInfo(KeyBasicInfo keyBasicInfo, UserKeyInfo userKeyInfo) {
//        KeyUserDao keyUserDao = new KeyUserImpl();
//        KeyUserData keyUserData = keyUserDao.findByUserid(String.valueOf(keyBasicInfo.getKeyId()));
//        HeartDao heartDao = new HeartImpl();
//        HeartData heartData = heartDao.findById(GlobalVariables.getInstance().getmSiteData().getSite(),
//                GlobalVariables.getInstance().getmSiteData().getLockid());
//        if (null == keyUserData && 0 == keyUserData.getId()) return null;
//
//        Date keyIssueTime = TimeUtils.dateFromNotYMDHMS(
//                HexUtil.encodeHexStr(keyBasicInfo.getKeyIssueTime()));
//        if (keyUserData.getEditime().getTime() > keyIssueTime.getTime()) {
//
//            keyBasicInfo.setBeginTime(TimeUtils.dateToBytesYMDHM(keyUserData.getEnd()));
//            keyBasicInfo.setEndTime(TimeUtils.dateToBytesYMDHM(keyUserData.getBegin()));
//            keyBasicInfo.setVerifyDay(Integer.valueOf(keyUserData.getValday()));
//
//
////        userKeyInfo.setKeyIssueTime(TimeUtils.dateToBytesYMDHM(new Date()));
//
////        if (null != heartData && heartData.getCalendar().getTime() > keyIssueTime.getTime()) {
////            CalendarDao calendarDao = new CalendarImpl();
////            List<CalendarData> calendarDataList = calendarDao.findByCalId(keyUserData.getCalendar());
////            if (null != calendarDataList) {
////                List<UserKeyInfo.CalendarInfo> calendarInfoList = new ArrayList<>();
////                for (CalendarData calendarData : calendarDataList) {
////                    Calendar calendar = Calendar.getInstance();
////                    calendar.setTime(calendarData.getCalendar());
////                    calendarInfoList.add(new UserKeyInfo.CalendarInfo(calendar, calendarData.getType()));
////                }
////                userKeyInfo.setCalendarInfo(calendarInfoList);
////            }
////        }
//            if (null != heartData && heartData.getTimezone().getTime() > keyIssueTime.getTime()) {
//
//            }
//            if (null != heartData && heartData.getDst().getTime() > keyIssueTime.getTime()) {
//                DSTDao dstDao = new DSTImpl();
//                DSTData dstData = dstDao.find();
//                if (dstData != null && dstData.getEnable() == 0) {
//                    Calendar begin = Calendar.getInstance();
//                    Calendar end = Calendar.getInstance();
//                    begin.setTime(dstData.getBegin());
//                    end.setTime(dstData.getEnd());
//                    UserKeyInfo.DSTInfo dstInfo = new UserKeyInfo.DSTInfo();
//                    dstInfo.BeginDate = begin;
//                    dstInfo.EndDate = end;
//                    mUserKeyInfo.setDST(dstInfo);
//
//                }
//            }
//            KeyTimeDao keyTimeDao = new KeyTimeImpl();
//            List<KeyTimezoneData> mList = keyTimeDao.findAll();
//            if (mList.size() != 0) {
//                List<UserKeyInfo.TimezoneInfo> timeList = new ArrayList<UserKeyInfo.TimezoneInfo>();
//                List<UserKeyInfo.ZoneInfo> zoneList = new ArrayList<UserKeyInfo.ZoneInfo>();
//
//                for (int z = 0, pos = 0; z < mList.size() / 12; z = z + 1, pos = pos + 12) {
//                    for (int t = pos; t < pos + 12; t++) {
//                        UserKeyInfo.TimezoneInfo time = new UserKeyInfo.TimezoneInfo();
////                    Date date = new Date(13, 5, 00, 00, 00);
//                        time.ZoneNo = mList.get(t).getNo();
//                        time.TimeNo = mList.get(t).getSerial();
//                        time.From.setTime(mList.get(t).getFrom());
////                    date = new Date(18, 8, 19, 23, 59);
//                        time.To.setTime(mList.get(t).getTo());
//                        if (mList.get(t).getSun() == 1) {
//                            time.Su = true;
//                        } else {
//                            time.Su = false;
//                        }
//                        if (mList.get(t).getMon() == 1) {
//                            time.Mo = true;
//                        } else {
//                            time.Mo = false;
//                        }
//                        if (mList.get(t).getTue() == 1) {
//                            time.Tu = true;
//                        } else {
//                            time.Tu = false;
//                        }
//                        if (mList.get(t).getWed() == 1) {
//                            time.We = true;
//                        } else {
//                            time.We = false;
//                        }
//                        if (mList.get(t).getThu() == 1) {
//                            time.Th = true;
//                        } else {
//                            time.Th = false;
//                        }
//                        if (mList.get(t).getFri() == 1) {
//                            time.Fr = true;
//                        } else {
//                            time.Fr = false;
//                        }
//                        if (mList.get(t).getSat() == 1) {
//                            time.Sa = true;
//                        } else {
//                            time.Sa = false;
//                        }
//                        if (mList.get(t).getHol() == 1) {
//                            time.Hol = true;
//                        } else {
//                            time.Hol = false;
//                        }
//                        if (mList.get(t).getSp1() == 1) {
//                            time.Sp1 = true;
//                        } else {
//                            time.Sp1 = false;
//                        }
//                        if (mList.get(t).getSp2() == 1) {
//                            time.Sp2 = true;
//                        } else {
//                            time.Sp2 = false;
//                        }
//                        timeList.add(time);
//                    }
//                    UserKeyInfo.ZoneInfo zone = new UserKeyInfo.ZoneInfo();
//                    zone.ZoneNo = z + 1;
//                    zone.TimeCount = 12;
//                    zoneList.add(zone);
//                }
//                userKeyInfo.setTimezoneInfo(timeList);
//                userKeyInfo.setZoneInfo(zoneList);
//                userKeyInfo.setTimezoneCount(zoneList.size());
//            }
//            List<UserKeyInfo.Open> openList = new ArrayList<>();
//            PlanKeyDelDao keyDelDao = new PlanKeyDelImpl();
//            List<PlanKeyDelData> planKeyDelDataList = keyDelDao.findPlanKeyByUserId(keyBasicInfo.getKeyId());
//            if (null != planKeyDelDataList && planKeyDelDataList.size() > 0) {
//                StringBuilder sb = new StringBuilder(64);
//                for (PlanKeyDelData planKeyDelData : planKeyDelDataList) {
//                    sb.append(planKeyDelData.getData());
//                }
//                List<PlanKeyDel> keyDels = JSONArray.parseArray(sb.toString(), PlanKeyDel.class);
//                for (PlanKeyDel planKeyDel : keyDels) {
//                    openList.add(new UserKeyInfo.Open(Integer.valueOf(planKeyDel.getType()), Integer.valueOf(planKeyDel.getLockid()),
//                            0));
////                openList.add(new UserKeyInfo.Open(0, Integer.valueOf(planKeyDel.getType()), Integer.valueOf(planKeyDel.getLockid()),  Integer.valueOf(planKeyDel.getTimezoneid())));
//                    Log.e("deltimezone", planKeyDel.getLockid() + " " + planKeyDel.getTimezoneid() + " " + planKeyDel.getType());
//                }
//            }
//            PlanKeyAddDao keyAddDao = new PlanKeyAddImpl();
//            List<PlanKeyAddData> planKeyAddList = keyAddDao.findPlanKeyByUserId(keyBasicInfo.getKeyId());
//            if (null != planKeyAddList && planKeyAddList.size() > 0) {
//                StringBuilder sb = new StringBuilder(64);
//                for (PlanKeyAddData planKeyAddData : planKeyAddList) {
//                    sb.append(planKeyAddData.getData());
//                }
//                List<PlanKeyAdd> keyAdds = JSONArray.parseArray(sb.toString(), PlanKeyAdd.class);
//                for (PlanKeyAdd planKeyAdd : keyAdds) {
//                    openList.add(new UserKeyInfo.Open(Integer.valueOf(planKeyAdd.getType()), Integer.valueOf(planKeyAdd.getLockid()),
//                            Integer.valueOf(planKeyAdd.getTimezoneid())));
////                openList.add(new UserKeyInfo.Open(1, Integer.valueOf(planKeyAdd.getType()),Integer.valueOf(planKeyAdd.getLockid()),
////                        Integer.valueOf(planKeyAdd.getTimezoneid())));
//                    Log.e("addtimezone", planKeyAdd.getLockid() + " " + planKeyAdd.getTimezoneid() + " " + planKeyAdd.getType());
//                }
//            }
//            userKeyInfo.setOpens(openList);
//
//            keyBasicInfo.setKeyIssueTime(TimeUtils.dateToBytesYMDHM(new Date()));
////        PlanKeyTempDao planKeyTempDao = new PlanKeyTempImpl();
////
////        List<PlanKeyTempData> planKeyTempDataList = planKeyTempDao.findPlanKeyByUserId(keyBasicInfo.getKeyId());
////        List<UserKeyInfo.TempOpen> tempOpenList = new ArrayList<>();
////        if (null != planKeyTempDataList) {
////            StringBuilder sb = new StringBuilder(64);
////            for (PlanKeyTempData planKeyTempData : planKeyTempDataList) {
////                Calendar expiry = Calendar.getInstance();
////                Calendar from = Calendar.getInstance();
////                Calendar to = Calendar.getInstance();
////                expiry.setTime(planKeyTempData.getExpiry());
////                from.setTimeInMillis(planKeyTempData.getBegin().getTime());
////                to.setTimeInMillis(planKeyTempData.getEnd().getTime());
//////                to.setTime(planKeyTempData.getEnd());
////
////                Log.d("tempopen", TimeUtils.calToNotYMDWHMS(from) + "\n" + TimeUtils.calToNotYMDWHMS(to));
////                String[] locks = planKeyTempData.getTempPlan().split(",");
////                for (String lockId : locks) {
////                    tempOpenList.add(new UserKeyInfo.TempOpen(expiry, from, to, Integer.parseInt(lockId)));
////                }
////            }
////        }
////        userKeyInfo.setTempOpens(tempOpenList);
//
////        List<UserKeyInfo.TempOpen> tempList = new ArrayList<UserKeyInfo.TempOpen>();
////
////            UserKeyInfo.TempOpen topen = new UserKeyInfo.TempOpen();
////            topen.EndDate.add(Calendar.MONTH, 2);
////            topen.FromTime.set(Calendar.HOUR_OF_DAY, 8);
////            topen.FromTime.set(Calendar.MINUTE, 30);
////            topen.ToTime.set(Calendar.HOUR_OF_DAY, 22);
////            topen.ToTime.set(Calendar.MINUTE, 30);
////            topen.LockId = 4;
////            tempList.add(topen);
//
////        userKeyInfo.setTempOpens(tempList);
//        }
//        return userKeyInfo;
//    }
//
////    private UserCardInfo getUserCardInfo(CardBasicInfo cardBasicInfo, UserCardInfo userCardInfo) {
////        CardUserDao cardUserDao = new CardUserImpl();
////        CardUserData cardUserData = cardUserDao.findByUserId(cardBasicInfo.getCardId());
////        HeartDao heartDao = new HeartImpl();
////        HeartData heartData = heartDao.findById(GlobalVariables.getInstance().getmSiteData().getSite(),
////                GlobalVariables.getInstance().getmSiteData().getLockid());
////        if (null == cardUserData && 0 == cardUserData.getId()) return null;
////        userCardInfo.setCardIssueTime(TimeUtils.dateToBytesYMDHM(new Date()));
////        Date cardIssueTime = TimeUtils.dateFromNotYMDHM(HexUtil.encodeHexStr(userCardInfo.getCardIssueTime()));
////
////        if (cardUserData.getEditime().getTime() > cardIssueTime.getTime()) {
////            List<String> lockList = JSONArray.parseArray(cardUserData.getPlan(), String.class);
////            int[] locks = new int[40];
////            if (null != lockList && lockList.size() > 0) {
////                for (int i = 0; i < lockList.size(); i++) {
////                    locks[i] = Integer.valueOf(lockList.get(i));
////                }
////            }
////            userCardInfo.setLockList(locks);
////        }
////        if (null != heartData && heartData.getCardtime().getTime() > cardIssueTime.getTime()) {
////            CardTimeDao cardTimeDao = new CardTimeImpl();
////            List<CardTimezoneData> list = cardTimeDao.findByUserId(cardBasicInfo.getCardId());
////            if (null != list && list.size() > 0) {
////                List<CardBasicInfo.Timezone> timezones = new ArrayList<>();
////                for (CardTimezoneData cardTimezoneData : list) {
////                    CardBasicInfo.Timezone timezone = new CardBasicInfo.Timezone();
////                    Calendar calendar = Calendar.getInstance();
////                    calendar.setTime(cardUserData.getBegin());
////                    timezone.setBeginDate(calendar);
////                    calendar.setTime(cardUserData.getEnd());
////                    timezone.setEndDate(calendar);
////                    calendar.setTime(cardTimezoneData.getFrom());
////                    timezone.setBeginTime(calendar);
////                    calendar.setTime(cardTimezoneData.getTo());
////                    timezone.setEndTime(calendar);
////                    if (cardTimezoneData.getSun() == 1) timezone.setSu(true);
////                    else timezone.setSu(false);
////                    if (cardTimezoneData.getMon() == 1) timezone.setMo(true);
////                    else timezone.setMo(false);
////                    if (cardTimezoneData.getTue() == 1) timezone.setTu(true);
////                    else timezone.setTu(false);
////                    if (cardTimezoneData.getWed() == 1) timezone.setWe(true);
////                    else timezone.setWe(false);
////                    if (cardTimezoneData.getThu() == 1) timezone.setTh(true);
////                    else timezone.setTh(false);
////                    if (cardTimezoneData.getFri() == 1) timezone.setFr(true);
////                    else timezone.setFr(false);
////                    if (cardTimezoneData.getSat() == 1) timezone.setSa(true);
////                    else timezone.setSa(false);
////                }
////                userCardInfo.setTimeList(timezones);
////            }
////        }
////        return userCardInfo;
////    }
//
//    private OnPortListener.OnBeepListener mOnBeepListener = new OnPortListener.OnBeepListener() {
//        @Override
//        public void beepSuccess() {
//
//        }
//
//        @Override
//        public void beepFailed() {
//
//        }
//    };
//}
